package com.ccq.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.servlet.ModelAndView;

import com.ccq.domain.User;

@Controller
public class ThymeleafController {
	private static Log log = LogFactory.getLog(UserController.class);

	@PostMapping(value = "/jsr")
	public ModelAndView jsr303(@RequestBody @Validated User user, BindingResult result) {
		Map<String, Object> map = new HashMap<>();
		String msg = "success";
		if (result.hasErrors()) {
			log.error("erroMsg={}" + result.getAllErrors());
			msg = result.getAllErrors().get(0).getDefaultMessage();
		}
		map.put("msg", msg);
		return new ModelAndView("user/index", "map", map);
	}
}
